package jianzhiOffer;

import java.util.Deque;
import java.util.LinkedList;

public class num24 {
    public ListNode reverseList(ListNode head) {
        Deque<Integer> stack = new LinkedList<>();
        ListNode dummyhead = new ListNode(-1);
        ListNode node = head;
        while(node != null) {
            stack.push(node.val);
            node = node.next;
        }
        ListNode pre = dummyhead;
        while(!stack.isEmpty()) {
            ListNode root = new ListNode(stack.pop());
            pre.next = root;
            pre = pre.next;
        }
        return dummyhead.next;
    }
}
